<?php
/**
 * Created by PhpStorm.
 * User: 17208
 * Date: 2020/9/28
 * Time: 18:02
 */

namespace app\utility;


use app\model\TbPromoteSite;
use extend\Config;
use ETaobao\Factory;

class TaoBaoApp
{
    private static $instance = null;
    public static function get(){
        if(!self::$instance){
            self::$instance = self::create();
        }
        return self::$instance;
    }
    protected static function create(){

        $config = Config::get('taobao');
        $config = [
            'appkey' => $config['appkey'],
            'secretKey' => $config['secretKey'],
            'format' => 'json',
            'session' => '1',
            'sandbox' => false,

            'tkl_apikey'=>$config['taokouling']['apikey'],
            'tkl_uid'=>$config['taokouling']['uid']
        ];
        return Factory::Tbk($config);
    }
    public static function getPid(){
        $host = $_SERVER['SERVER_NAME'];
        $data = TbPromoteSite::get(['id','pid','adzone_id','site_id'],['host'=>$host]);
        !$data && $data = [
            'pid'=>Config::get('taobao.pid'),
            'adzone_id'=>Config::get('taobao.adzone_id'),
            'site_id'=>Config::get('taobao.site_id'),
        ];
        return $data;
    }
}